/* CodeBuilder代码生成器 创建时间：2011-11-05 22:40:35 */
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using Maticsoft.DBUtility;
namespace DAL
{
    /// <summary>
    /// 数据访问类:TB_User
    /// </summary>
    public partial class User
    {
        public User()
        { }
        #region  Method

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("ID", "TB_User");
        }

        /// <summary>
        /// 是否存在该ID记录
        /// </summary>
        /// <param name="Int32">主键</param>
        /// <returns>bool:True/False</returns>
        public bool Exists(Int32 ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from TB_User");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
            parameters[0].Value = ID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 是否存在该条件记录
        /// </summary>
        /// <param name="strWhere">Where条件</param>
        /// <returns>bool:True/False</returns>
        public bool Exists(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from TB_User");
            if (!string.IsNullOrEmpty(strWhere))
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Exists(strSql.ToString(), null);
        }

        /// <summary>
        /// 获取数量
        /// </summary>
        /// <returns>总记录数</returns>
        public int Count()
        {
            return Count(null);
        }

        /// <summary>
        /// 根据条件获取数量
        /// </summary>
        /// <param name="strWhere">Where条件</param>
        /// <returns>记录数</returns>
        public int Count(string strWhere)
        {
            string strSql = "select count(*) from TB_User";
            if (!string.IsNullOrEmpty(strWhere))
            {
                strSql += " where " + strWhere;
            }
            object obj = DbHelperSQL.GetSingle(strSql, null);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model">User实体对象</param>
        /// <returns>自动增长列</returns>
        public int Add(Model.User model)
        {
            string strSql = "insert into TB_User(";
            if (model.UserName != null) strSql += "UserName,";
            if (model.UserPassword != null) strSql += "UserPassword,";
            if (model.Question.HasValue) strSql += "Question,";
            if (model.Answer != null) strSql += "Answer,";
            if (model.UserType.HasValue) strSql += "UserType,";
            if (model.Integral.HasValue) strSql += "Integral,";
            if (model.IsPass.HasValue) strSql += "IsPass,";
            if (model.NickName != null) strSql += "NickName,";
            if (model.HeahImagePath != null) strSql += "HeahImagePath,";
            if (model.Sex.HasValue) strSql += "Sex,";
            if (model.Age.HasValue) strSql += "Age,";
            if (model.Occupation != null) strSql += "Occupation,";
            if (model.QQ != null) strSql += "QQ,";
            if (model.MSN != null) strSql += "MSN,";
            if (model.Height != null) strSql += "Height,";
            if (model.Tel != null) strSql += "Tel,";
            if (model.Measurements != null) strSql += "Measurements,";
            if (model.Constellation != null) strSql += "Constellation,";
            if (model.signa != null) strSql += "signa,";
            if (model.AreaID.HasValue) strSql += "AreaID,";
            if (model.NowInThe != null) strSql += "NowInThe,";
            if (model.Looks != null) strSql += "Looks,";
            if (model.LoveState.HasValue) strSql += "LoveState,";
            if (model.Birth.HasValue) strSql += "Birth,";
            if (model.School != null) strSql += "School,";
            if (model.PhoneModel != null) strSql += "PhoneModel,";
            if (model.CardMumber != null) strSql += "CardMumber,";
            if (model.LoveSnacks != null) strSql += "LoveSnacks,";
            if (model.LoveStar != null) strSql += "LoveStar,";
            if (model.LoveCuisines != null) strSql += "LoveCuisines,";
            if (model.LoveMovie != null) strSql += "LoveMovie,";
            if (model.LikeObject != null) strSql += "LikeObject,";
            if (model.MessObject != null) strSql += "MessObject,";
            if (model.VentObject != null) strSql += "VentObject,";
            if (model.LoveMusicStyle != null) strSql += "LoveMusicStyle,";
            if (model.AddTime.HasValue) strSql += "AddTime,";
            strSql = System.Text.RegularExpressions.Regex.Replace(strSql, ",$", "");
            strSql += ") values (";
            if (model.UserName != null) strSql += "@UserName,";
            if (model.UserPassword != null) strSql += "@UserPassword,";
            if (model.Question.HasValue) strSql += "@Question,";
            if (model.Answer != null) strSql += "@Answer,";
            if (model.UserType.HasValue) strSql += "@UserType,";
            if (model.Integral.HasValue) strSql += "@Integral,";
            if (model.IsPass.HasValue) strSql += "@IsPass,";
            if (model.NickName != null) strSql += "@NickName,";
            if (model.HeahImagePath != null) strSql += "@HeahImagePath,";
            if (model.Sex.HasValue) strSql += "@Sex,";
            if (model.Age.HasValue) strSql += "@Age,";
            if (model.Occupation != null) strSql += "@Occupation,";
            if (model.QQ != null) strSql += "@QQ,";
            if (model.MSN != null) strSql += "@MSN,";
            if (model.Height != null) strSql += "@Height,";
            if (model.Tel != null) strSql += "@Tel,";
            if (model.Measurements != null) strSql += "@Measurements,";
            if (model.Constellation != null) strSql += "@Constellation,";
            if (model.signa != null) strSql += "@signa,";
            if (model.AreaID.HasValue) strSql += "@AreaID,";
            if (model.NowInThe != null) strSql += "@NowInThe,";
            if (model.Looks != null) strSql += "@Looks,";
            if (model.LoveState.HasValue) strSql += "@LoveState,";
            if (model.Birth.HasValue) strSql += "@Birth,";
            if (model.School != null) strSql += "@School,";
            if (model.PhoneModel != null) strSql += "@PhoneModel,";
            if (model.CardMumber != null) strSql += "@CardMumber,";
            if (model.LoveSnacks != null) strSql += "@LoveSnacks,";
            if (model.LoveStar != null) strSql += "@LoveStar,";
            if (model.LoveCuisines != null) strSql += "@LoveCuisines,";
            if (model.LoveMovie != null) strSql += "@LoveMovie,";
            if (model.LikeObject != null) strSql += "@LikeObject,";
            if (model.MessObject != null) strSql += "@MessObject,";
            if (model.VentObject != null) strSql += "@VentObject,";
            if (model.LoveMusicStyle != null) strSql += "@LoveMusicStyle,";
            if (model.AddTime.HasValue) strSql += "@AddTime,";
            strSql = System.Text.RegularExpressions.Regex.Replace(strSql, ",$", "");
            strSql += ");select @@IDENTITY";

            List<SqlParameter> paralist = new List<SqlParameter>();
            if (model.UserName != null)
            {
                SqlParameter para = new SqlParameter("@UserName", SqlDbType.NVarChar, 200);
                para.Value = model.UserName;
                paralist.Add(para);
            }
            if (model.UserPassword != null)
            {
                SqlParameter para = new SqlParameter("@UserPassword", SqlDbType.NVarChar, 200);
                para.Value = model.UserPassword;
                paralist.Add(para);
            }
            if (model.Question.HasValue)
            {
                SqlParameter para = new SqlParameter("@Question", SqlDbType.Int, 4);
                para.Value = model.Question;
                paralist.Add(para);
            }
            if (model.Answer != null)
            {
                SqlParameter para = new SqlParameter("@Answer", SqlDbType.NVarChar, 200);
                para.Value = model.Answer;
                paralist.Add(para);
            }
            if (model.UserType.HasValue)
            {
                SqlParameter para = new SqlParameter("@UserType", SqlDbType.Int, 4);
                para.Value = model.UserType;
                paralist.Add(para);
            }
            if (model.Integral.HasValue)
            {
                SqlParameter para = new SqlParameter("@Integral", SqlDbType.Int, 4);
                para.Value = model.Integral;
                paralist.Add(para);
            }
            if (model.IsPass.HasValue)
            {
                SqlParameter para = new SqlParameter("@IsPass", SqlDbType.Bit, 1);
                para.Value = model.IsPass;
                paralist.Add(para);
            }
            if (model.NickName != null)
            {
                SqlParameter para = new SqlParameter("@NickName", SqlDbType.NVarChar, 200);
                para.Value = model.NickName;
                paralist.Add(para);
            }
            if (model.HeahImagePath != null)
            {
                SqlParameter para = new SqlParameter("@HeahImagePath", SqlDbType.NVarChar, 200);
                para.Value = model.HeahImagePath;
                paralist.Add(para);
            }
            if (model.Sex.HasValue)
            {
                SqlParameter para = new SqlParameter("@Sex", SqlDbType.Int, 4);
                para.Value = model.Sex;
                paralist.Add(para);
            }
            if (model.Age.HasValue)
            {
                SqlParameter para = new SqlParameter("@Age", SqlDbType.Int, 4);
                para.Value = model.Age;
                paralist.Add(para);
            }
            if (model.Occupation != null)
            {
                SqlParameter para = new SqlParameter("@Occupation", SqlDbType.NVarChar, 200);
                para.Value = model.Occupation;
                paralist.Add(para);
            }
            if (model.QQ != null)
            {
                SqlParameter para = new SqlParameter("@QQ", SqlDbType.NVarChar, 200);
                para.Value = model.QQ;
                paralist.Add(para);
            }
            if (model.MSN != null)
            {
                SqlParameter para = new SqlParameter("@MSN", SqlDbType.NVarChar, 200);
                para.Value = model.MSN;
                paralist.Add(para);
            }
            if (model.Height != null)
            {
                SqlParameter para = new SqlParameter("@Height", SqlDbType.NVarChar, 200);
                para.Value = model.Height;
                paralist.Add(para);
            }
            if (model.Tel != null)
            {
                SqlParameter para = new SqlParameter("@Tel", SqlDbType.NVarChar, 50);
                para.Value = model.Tel;
                paralist.Add(para);
            }
            if (model.Measurements != null)
            {
                SqlParameter para = new SqlParameter("@Measurements", SqlDbType.NVarChar, 200);
                para.Value = model.Measurements;
                paralist.Add(para);
            }
            if (model.Constellation != null)
            {
                SqlParameter para = new SqlParameter("@Constellation", SqlDbType.NVarChar, 200);
                para.Value = model.Constellation;
                paralist.Add(para);
            }
            if (model.signa != null)
            {
                SqlParameter para = new SqlParameter("@signa", SqlDbType.NVarChar, 200);
                para.Value = model.signa;
                paralist.Add(para);
            }
            if (model.AreaID.HasValue)
            {
                SqlParameter para = new SqlParameter("@AreaID", SqlDbType.BigInt, 8);
                para.Value = model.AreaID;
                paralist.Add(para);
            }
            if (model.NowInThe != null)
            {
                SqlParameter para = new SqlParameter("@NowInThe", SqlDbType.NVarChar, 500);
                para.Value = model.NowInThe;
                paralist.Add(para);
            }
            if (model.Looks != null)
            {
                SqlParameter para = new SqlParameter("@Looks", SqlDbType.NVarChar, 500);
                para.Value = model.Looks;
                paralist.Add(para);
            }
            if (model.LoveState.HasValue)
            {
                SqlParameter para = new SqlParameter("@LoveState", SqlDbType.Int, 4);
                para.Value = model.LoveState;
                paralist.Add(para);
            }
            if (model.Birth.HasValue)
            {
                SqlParameter para = new SqlParameter("@Birth", SqlDbType.SmallDateTime, 4);
                para.Value = model.Birth;
                paralist.Add(para);
            }
            if (model.School != null)
            {
                SqlParameter para = new SqlParameter("@School", SqlDbType.NVarChar, 200);
                para.Value = model.School;
                paralist.Add(para);
            }
            if (model.PhoneModel != null)
            {
                SqlParameter para = new SqlParameter("@PhoneModel", SqlDbType.NVarChar, 200);
                para.Value = model.PhoneModel;
                paralist.Add(para);
            }
            if (model.CardMumber != null)
            {
                SqlParameter para = new SqlParameter("@CardMumber", SqlDbType.NVarChar, 18);
                para.Value = model.CardMumber;
                paralist.Add(para);
            }
            if (model.LoveSnacks != null)
            {
                SqlParameter para = new SqlParameter("@LoveSnacks", SqlDbType.NVarChar, 500);
                para.Value = model.LoveSnacks;
                paralist.Add(para);
            }
            if (model.LoveStar != null)
            {
                SqlParameter para = new SqlParameter("@LoveStar", SqlDbType.NVarChar, 500);
                para.Value = model.LoveStar;
                paralist.Add(para);
            }
            if (model.LoveCuisines != null)
            {
                SqlParameter para = new SqlParameter("@LoveCuisines", SqlDbType.NVarChar, 500);
                para.Value = model.LoveCuisines;
                paralist.Add(para);
            }
            if (model.LoveMovie != null)
            {
                SqlParameter para = new SqlParameter("@LoveMovie", SqlDbType.NVarChar, 500);
                para.Value = model.LoveMovie;
                paralist.Add(para);
            }
            if (model.LikeObject != null)
            {
                SqlParameter para = new SqlParameter("@LikeObject", SqlDbType.NVarChar, 500);
                para.Value = model.LikeObject;
                paralist.Add(para);
            }
            if (model.MessObject != null)
            {
                SqlParameter para = new SqlParameter("@MessObject", SqlDbType.NVarChar, 500);
                para.Value = model.MessObject;
                paralist.Add(para);
            }
            if (model.VentObject != null)
            {
                SqlParameter para = new SqlParameter("@VentObject", SqlDbType.NVarChar, 500);
                para.Value = model.VentObject;
                paralist.Add(para);
            }
            if (model.LoveMusicStyle != null)
            {
                SqlParameter para = new SqlParameter("@LoveMusicStyle", SqlDbType.NVarChar, 500);
                para.Value = model.LoveMusicStyle;
                paralist.Add(para);
            }
            if (model.AddTime.HasValue)
            {
                SqlParameter para = new SqlParameter("@AddTime", SqlDbType.DateTime, 8);
                para.Value = model.AddTime;
                paralist.Add(para);
            }

            object obj = DbHelperSQL.GetSingle(strSql, paralist.ToArray());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model">User实体对象</param>
        /// <param name="strWhere">Where条件</param>
        /// <returns>修改条数</returns>
        public int Update(Model.User model, string strWhere)
        {
            string strSql = "update TB_User set ";
            if (model.UserName != null) strSql += "UserName=@UserName,";
            if (model.UserPassword != null) strSql += "UserPassword=@UserPassword,";
            if (model.Question.HasValue) strSql += "Question=@Question,";
            if (model.Answer != null) strSql += "Answer=@Answer,";
            if (model.UserType.HasValue) strSql += "UserType=@UserType,";
            if (model.Integral.HasValue) strSql += "Integral=@Integral,";
            if (model.IsPass.HasValue) strSql += "IsPass=@IsPass,";
            if (model.NickName != null) strSql += "NickName=@NickName,";
            if (model.HeahImagePath != null) strSql += "HeahImagePath=@HeahImagePath,";
            if (model.Sex.HasValue) strSql += "Sex=@Sex,";
            if (model.Age.HasValue) strSql += "Age=@Age,";
            if (model.Occupation != null) strSql += "Occupation=@Occupation,";
            if (model.QQ != null) strSql += "QQ=@QQ,";
            if (model.MSN != null) strSql += "MSN=@MSN,";
            if (model.Height != null) strSql += "Height=@Height,";
            if (model.Tel != null) strSql += "Tel=@Tel,";
            if (model.Measurements != null) strSql += "Measurements=@Measurements,";
            if (model.Constellation != null) strSql += "Constellation=@Constellation,";
            if (model.signa != null) strSql += "signa=@signa,";
            if (model.AreaID.HasValue) strSql += "AreaID=@AreaID,";
            if (model.NowInThe != null) strSql += "NowInThe=@NowInThe,";
            if (model.Looks != null) strSql += "Looks=@Looks,";
            if (model.LoveState.HasValue) strSql += "LoveState=@LoveState,";
            if (model.Birth.HasValue) strSql += "Birth=@Birth,";
            if (model.School != null) strSql += "School=@School,";
            if (model.PhoneModel != null) strSql += "PhoneModel=@PhoneModel,";
            if (model.CardMumber != null) strSql += "CardMumber=@CardMumber,";
            if (model.LoveSnacks != null) strSql += "LoveSnacks=@LoveSnacks,";
            if (model.LoveStar != null) strSql += "LoveStar=@LoveStar,";
            if (model.LoveCuisines != null) strSql += "LoveCuisines=@LoveCuisines,";
            if (model.LoveMovie != null) strSql += "LoveMovie=@LoveMovie,";
            if (model.LikeObject != null) strSql += "LikeObject=@LikeObject,";
            if (model.MessObject != null) strSql += "MessObject=@MessObject,";
            if (model.VentObject != null) strSql += "VentObject=@VentObject,";
            if (model.LoveMusicStyle != null) strSql += "LoveMusicStyle=@LoveMusicStyle,";
            if (model.AddTime.HasValue) strSql += "AddTime=@AddTime,";
            strSql = System.Text.RegularExpressions.Regex.Replace(strSql, ",$", "");
            if (!string.IsNullOrEmpty(strWhere))
            {
                strSql += " where " + strWhere;
            }

            List<SqlParameter> paralist = new List<SqlParameter>();
            if (model.UserName != null)
            {
                SqlParameter para = new SqlParameter("@UserName", SqlDbType.NVarChar, 200);
                para.Value = model.UserName;
                paralist.Add(para);
            }
            if (model.UserPassword != null)
            {
                SqlParameter para = new SqlParameter("@UserPassword", SqlDbType.NVarChar, 200);
                para.Value = model.UserPassword;
                paralist.Add(para);
            }
            if (model.Question.HasValue)
            {
                SqlParameter para = new SqlParameter("@Question", SqlDbType.Int, 4);
                para.Value = model.Question;
                paralist.Add(para);
            }
            if (model.Answer != null)
            {
                SqlParameter para = new SqlParameter("@Answer", SqlDbType.NVarChar, 200);
                para.Value = model.Answer;
                paralist.Add(para);
            }
            if (model.UserType.HasValue)
            {
                SqlParameter para = new SqlParameter("@UserType", SqlDbType.Int, 4);
                para.Value = model.UserType;
                paralist.Add(para);
            }
            if (model.Integral.HasValue)
            {
                SqlParameter para = new SqlParameter("@Integral", SqlDbType.Int, 4);
                para.Value = model.Integral;
                paralist.Add(para);
            }
            if (model.IsPass.HasValue)
            {
                SqlParameter para = new SqlParameter("@IsPass", SqlDbType.Bit, 1);
                para.Value = model.IsPass;
                paralist.Add(para);
            }
            if (model.NickName != null)
            {
                SqlParameter para = new SqlParameter("@NickName", SqlDbType.NVarChar, 200);
                para.Value = model.NickName;
                paralist.Add(para);
            }
            if (model.HeahImagePath != null)
            {
                SqlParameter para = new SqlParameter("@HeahImagePath", SqlDbType.NVarChar, 200);
                para.Value = model.HeahImagePath;
                paralist.Add(para);
            }
            if (model.Sex.HasValue)
            {
                SqlParameter para = new SqlParameter("@Sex", SqlDbType.Int, 4);
                para.Value = model.Sex;
                paralist.Add(para);
            }
            if (model.Age.HasValue)
            {
                SqlParameter para = new SqlParameter("@Age", SqlDbType.Int, 4);
                para.Value = model.Age;
                paralist.Add(para);
            }
            if (model.Occupation != null)
            {
                SqlParameter para = new SqlParameter("@Occupation", SqlDbType.NVarChar, 200);
                para.Value = model.Occupation;
                paralist.Add(para);
            }
            if (model.QQ != null)
            {
                SqlParameter para = new SqlParameter("@QQ", SqlDbType.NVarChar, 200);
                para.Value = model.QQ;
                paralist.Add(para);
            }
            if (model.MSN != null)
            {
                SqlParameter para = new SqlParameter("@MSN", SqlDbType.NVarChar, 200);
                para.Value = model.MSN;
                paralist.Add(para);
            }
            if (model.Height != null)
            {
                SqlParameter para = new SqlParameter("@Height", SqlDbType.NVarChar, 200);
                para.Value = model.Height;
                paralist.Add(para);
            }
            if (model.Tel != null)
            {
                SqlParameter para = new SqlParameter("@Tel", SqlDbType.NVarChar, 50);
                para.Value = model.Tel;
                paralist.Add(para);
            }
            if (model.Measurements != null)
            {
                SqlParameter para = new SqlParameter("@Measurements", SqlDbType.NVarChar, 200);
                para.Value = model.Measurements;
                paralist.Add(para);
            }
            if (model.Constellation != null)
            {
                SqlParameter para = new SqlParameter("@Constellation", SqlDbType.NVarChar, 200);
                para.Value = model.Constellation;
                paralist.Add(para);
            }
            if (model.signa != null)
            {
                SqlParameter para = new SqlParameter("@signa", SqlDbType.NVarChar, 200);
                para.Value = model.signa;
                paralist.Add(para);
            }
            if (model.AreaID.HasValue)
            {
                SqlParameter para = new SqlParameter("@AreaID", SqlDbType.BigInt, 8);
                para.Value = model.AreaID;
                paralist.Add(para);
            }
            if (model.NowInThe != null)
            {
                SqlParameter para = new SqlParameter("@NowInThe", SqlDbType.NVarChar, 500);
                para.Value = model.NowInThe;
                paralist.Add(para);
            }
            if (model.Looks != null)
            {
                SqlParameter para = new SqlParameter("@Looks", SqlDbType.NVarChar, 500);
                para.Value = model.Looks;
                paralist.Add(para);
            }
            if (model.LoveState.HasValue)
            {
                SqlParameter para = new SqlParameter("@LoveState", SqlDbType.Int, 4);
                para.Value = model.LoveState;
                paralist.Add(para);
            }
            if (model.Birth.HasValue)
            {
                SqlParameter para = new SqlParameter("@Birth", SqlDbType.SmallDateTime, 4);
                para.Value = model.Birth;
                paralist.Add(para);
            }
            if (model.School != null)
            {
                SqlParameter para = new SqlParameter("@School", SqlDbType.NVarChar, 200);
                para.Value = model.School;
                paralist.Add(para);
            }
            if (model.PhoneModel != null)
            {
                SqlParameter para = new SqlParameter("@PhoneModel", SqlDbType.NVarChar, 200);
                para.Value = model.PhoneModel;
                paralist.Add(para);
            }
            if (model.CardMumber != null)
            {
                SqlParameter para = new SqlParameter("@CardMumber", SqlDbType.NVarChar, 18);
                para.Value = model.CardMumber;
                paralist.Add(para);
            }
            if (model.LoveSnacks != null)
            {
                SqlParameter para = new SqlParameter("@LoveSnacks", SqlDbType.NVarChar, 500);
                para.Value = model.LoveSnacks;
                paralist.Add(para);
            }
            if (model.LoveStar != null)
            {
                SqlParameter para = new SqlParameter("@LoveStar", SqlDbType.NVarChar, 500);
                para.Value = model.LoveStar;
                paralist.Add(para);
            }
            if (model.LoveCuisines != null)
            {
                SqlParameter para = new SqlParameter("@LoveCuisines", SqlDbType.NVarChar, 500);
                para.Value = model.LoveCuisines;
                paralist.Add(para);
            }
            if (model.LoveMovie != null)
            {
                SqlParameter para = new SqlParameter("@LoveMovie", SqlDbType.NVarChar, 500);
                para.Value = model.LoveMovie;
                paralist.Add(para);
            }
            if (model.LikeObject != null)
            {
                SqlParameter para = new SqlParameter("@LikeObject", SqlDbType.NVarChar, 500);
                para.Value = model.LikeObject;
                paralist.Add(para);
            }
            if (model.MessObject != null)
            {
                SqlParameter para = new SqlParameter("@MessObject", SqlDbType.NVarChar, 500);
                para.Value = model.MessObject;
                paralist.Add(para);
            }
            if (model.VentObject != null)
            {
                SqlParameter para = new SqlParameter("@VentObject", SqlDbType.NVarChar, 500);
                para.Value = model.VentObject;
                paralist.Add(para);
            }
            if (model.LoveMusicStyle != null)
            {
                SqlParameter para = new SqlParameter("@LoveMusicStyle", SqlDbType.NVarChar, 500);
                para.Value = model.LoveMusicStyle;
                paralist.Add(para);
            }
            if (model.AddTime.HasValue)
            {
                SqlParameter para = new SqlParameter("@AddTime", SqlDbType.DateTime, 8);
                para.Value = model.AddTime;
                paralist.Add(para);
            }

            int rows = DbHelperSQL.ExecuteSql(strSql, paralist.ToArray());
            return rows;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        /// <param name="Int32">主键</param>
        /// <returns>bool:True/False</returns>
        public bool Delete(Int32 ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from TB_User ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
            parameters[0].Value = ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="strWhere">Where条件</param>
        /// <returns>删除条数</returns>
        public int DeleteList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from TB_User ");
            if (!string.IsNullOrEmpty(strWhere))
            {
                strSql.Append("where " + strWhere);
            }
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            return rows;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.User GetModel(Int32 ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ID,UserName,UserPassword,Question,Answer,UserType,Integral,IsPass,NickName,HeahImagePath,Sex,Age,Occupation,QQ,MSN,Height,Tel,Measurements,Constellation,signa,AreaID,NowInThe,Looks,LoveState,Birth,School,PhoneModel,CardMumber,LoveSnacks,LoveStar,LoveCuisines,LoveMovie,LikeObject,MessObject,VentObject,LoveMusicStyle,AddTime from TB_User ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)
            };
            parameters[0].Value = ID;

            Model.User model = new Model.User();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UserName"].ToString() != "")
                {
                    model.UserName = ds.Tables[0].Rows[0]["UserName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserPassword"].ToString() != "")
                {
                    model.UserPassword = ds.Tables[0].Rows[0]["UserPassword"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Question"].ToString() != "")
                {
                    model.Question = int.Parse(ds.Tables[0].Rows[0]["Question"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Answer"].ToString() != "")
                {
                    model.Answer = ds.Tables[0].Rows[0]["Answer"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserType"].ToString() != "")
                {
                    model.UserType = int.Parse(ds.Tables[0].Rows[0]["UserType"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Integral"].ToString() != "")
                {
                    model.Integral = int.Parse(ds.Tables[0].Rows[0]["Integral"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsPass"].ToString() != "")
                {
                    model.IsPass = bool.Parse(ds.Tables[0].Rows[0]["IsPass"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NickName"].ToString() != "")
                {
                    model.NickName = ds.Tables[0].Rows[0]["NickName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["HeahImagePath"].ToString() != "")
                {
                    model.HeahImagePath = ds.Tables[0].Rows[0]["HeahImagePath"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Sex"].ToString() != "")
                {
                    model.Sex = int.Parse(ds.Tables[0].Rows[0]["Sex"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Age"].ToString() != "")
                {
                    model.Age = int.Parse(ds.Tables[0].Rows[0]["Age"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Occupation"].ToString() != "")
                {
                    model.Occupation = ds.Tables[0].Rows[0]["Occupation"].ToString();
                }
                if (ds.Tables[0].Rows[0]["QQ"].ToString() != "")
                {
                    model.QQ = ds.Tables[0].Rows[0]["QQ"].ToString();
                }
                if (ds.Tables[0].Rows[0]["MSN"].ToString() != "")
                {
                    model.MSN = ds.Tables[0].Rows[0]["MSN"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Height"].ToString() != "")
                {
                    model.Height = ds.Tables[0].Rows[0]["Height"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Tel"].ToString() != "")
                {
                    model.Tel = ds.Tables[0].Rows[0]["Tel"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Measurements"].ToString() != "")
                {
                    model.Measurements = ds.Tables[0].Rows[0]["Measurements"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Constellation"].ToString() != "")
                {
                    model.Constellation = ds.Tables[0].Rows[0]["Constellation"].ToString();
                }
                if (ds.Tables[0].Rows[0]["signa"].ToString() != "")
                {
                    model.signa = ds.Tables[0].Rows[0]["signa"].ToString();
                }
                if (ds.Tables[0].Rows[0]["AreaID"].ToString() != "")
                {
                    model.AreaID = Int64.Parse(ds.Tables[0].Rows[0]["AreaID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NowInThe"].ToString() != "")
                {
                    model.NowInThe = ds.Tables[0].Rows[0]["NowInThe"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Looks"].ToString() != "")
                {
                    model.Looks = ds.Tables[0].Rows[0]["Looks"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LoveState"].ToString() != "")
                {
                    model.LoveState = int.Parse(ds.Tables[0].Rows[0]["LoveState"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Birth"].ToString() != "")
                {
                    model.Birth = DateTime.Parse(ds.Tables[0].Rows[0]["Birth"].ToString());
                }
                if (ds.Tables[0].Rows[0]["School"].ToString() != "")
                {
                    model.School = ds.Tables[0].Rows[0]["School"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PhoneModel"].ToString() != "")
                {
                    model.PhoneModel = ds.Tables[0].Rows[0]["PhoneModel"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CardMumber"].ToString() != "")
                {
                    model.CardMumber = ds.Tables[0].Rows[0]["CardMumber"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LoveSnacks"].ToString() != "")
                {
                    model.LoveSnacks = ds.Tables[0].Rows[0]["LoveSnacks"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LoveStar"].ToString() != "")
                {
                    model.LoveStar = ds.Tables[0].Rows[0]["LoveStar"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LoveCuisines"].ToString() != "")
                {
                    model.LoveCuisines = ds.Tables[0].Rows[0]["LoveCuisines"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LoveMovie"].ToString() != "")
                {
                    model.LoveMovie = ds.Tables[0].Rows[0]["LoveMovie"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LikeObject"].ToString() != "")
                {
                    model.LikeObject = ds.Tables[0].Rows[0]["LikeObject"].ToString();
                }
                if (ds.Tables[0].Rows[0]["MessObject"].ToString() != "")
                {
                    model.MessObject = ds.Tables[0].Rows[0]["MessObject"].ToString();
                }
                if (ds.Tables[0].Rows[0]["VentObject"].ToString() != "")
                {
                    model.VentObject = ds.Tables[0].Rows[0]["VentObject"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LoveMusicStyle"].ToString() != "")
                {
                    model.LoveMusicStyle = ds.Tables[0].Rows[0]["LoveMusicStyle"].ToString();
                }
                if (ds.Tables[0].Rows[0]["AddTime"].ToString() != "")
                {
                    model.AddTime = DateTime.Parse(ds.Tables[0].Rows[0]["AddTime"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        public Model.User GetModel(string where)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ID,UserName,UserPassword,Question,Answer,UserType,Integral,IsPass,NickName,HeahImagePath,Sex,Age,Occupation,QQ,MSN,Height,Tel,Measurements,Constellation,signa,AreaID,NowInThe,Looks,LoveState,Birth,School,PhoneModel,CardMumber,LoveSnacks,LoveStar,LoveCuisines,LoveMovie,LikeObject,MessObject,VentObject,LoveMusicStyle,AddTime from TB_User ");
            strSql.Append(" where " + where);
            Model.User model = new Model.User();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), null);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UserName"].ToString() != "")
                {
                    model.UserName = ds.Tables[0].Rows[0]["UserName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserPassword"].ToString() != "")
                {
                    model.UserPassword = ds.Tables[0].Rows[0]["UserPassword"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Question"].ToString() != "")
                {
                    model.Question = int.Parse(ds.Tables[0].Rows[0]["Question"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Answer"].ToString() != "")
                {
                    model.Answer = ds.Tables[0].Rows[0]["Answer"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserType"].ToString() != "")
                {
                    model.UserType = int.Parse(ds.Tables[0].Rows[0]["UserType"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Integral"].ToString() != "")
                {
                    model.Integral = int.Parse(ds.Tables[0].Rows[0]["Integral"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsPass"].ToString() != "")
                {
                    model.IsPass = bool.Parse(ds.Tables[0].Rows[0]["IsPass"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NickName"].ToString() != "")
                {
                    model.NickName = ds.Tables[0].Rows[0]["NickName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["HeahImagePath"].ToString() != "")
                {
                    model.HeahImagePath = ds.Tables[0].Rows[0]["HeahImagePath"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Sex"].ToString() != "")
                {
                    model.Sex = int.Parse(ds.Tables[0].Rows[0]["Sex"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Age"].ToString() != "")
                {
                    model.Age = int.Parse(ds.Tables[0].Rows[0]["Age"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Occupation"].ToString() != "")
                {
                    model.Occupation = ds.Tables[0].Rows[0]["Occupation"].ToString();
                }
                if (ds.Tables[0].Rows[0]["QQ"].ToString() != "")
                {
                    model.QQ = ds.Tables[0].Rows[0]["QQ"].ToString();
                }
                if (ds.Tables[0].Rows[0]["MSN"].ToString() != "")
                {
                    model.MSN = ds.Tables[0].Rows[0]["MSN"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Height"].ToString() != "")
                {
                    model.Height = ds.Tables[0].Rows[0]["Height"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Tel"].ToString() != "")
                {
                    model.Tel = ds.Tables[0].Rows[0]["Tel"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Measurements"].ToString() != "")
                {
                    model.Measurements = ds.Tables[0].Rows[0]["Measurements"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Constellation"].ToString() != "")
                {
                    model.Constellation = ds.Tables[0].Rows[0]["Constellation"].ToString();
                }
                if (ds.Tables[0].Rows[0]["signa"].ToString() != "")
                {
                    model.signa = ds.Tables[0].Rows[0]["signa"].ToString();
                }
                if (ds.Tables[0].Rows[0]["AreaID"].ToString() != "")
                {
                    model.AreaID = Int64.Parse(ds.Tables[0].Rows[0]["AreaID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NowInThe"].ToString() != "")
                {
                    model.NowInThe = ds.Tables[0].Rows[0]["NowInThe"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Looks"].ToString() != "")
                {
                    model.Looks = ds.Tables[0].Rows[0]["Looks"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LoveState"].ToString() != "")
                {
                    model.LoveState = int.Parse(ds.Tables[0].Rows[0]["LoveState"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Birth"].ToString() != "")
                {
                    model.Birth = DateTime.Parse(ds.Tables[0].Rows[0]["Birth"].ToString());
                }
                if (ds.Tables[0].Rows[0]["School"].ToString() != "")
                {
                    model.School = ds.Tables[0].Rows[0]["School"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PhoneModel"].ToString() != "")
                {
                    model.PhoneModel = ds.Tables[0].Rows[0]["PhoneModel"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CardMumber"].ToString() != "")
                {
                    model.CardMumber = ds.Tables[0].Rows[0]["CardMumber"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LoveSnacks"].ToString() != "")
                {
                    model.LoveSnacks = ds.Tables[0].Rows[0]["LoveSnacks"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LoveStar"].ToString() != "")
                {
                    model.LoveStar = ds.Tables[0].Rows[0]["LoveStar"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LoveCuisines"].ToString() != "")
                {
                    model.LoveCuisines = ds.Tables[0].Rows[0]["LoveCuisines"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LoveMovie"].ToString() != "")
                {
                    model.LoveMovie = ds.Tables[0].Rows[0]["LoveMovie"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LikeObject"].ToString() != "")
                {
                    model.LikeObject = ds.Tables[0].Rows[0]["LikeObject"].ToString();
                }
                if (ds.Tables[0].Rows[0]["MessObject"].ToString() != "")
                {
                    model.MessObject = ds.Tables[0].Rows[0]["MessObject"].ToString();
                }
                if (ds.Tables[0].Rows[0]["VentObject"].ToString() != "")
                {
                    model.VentObject = ds.Tables[0].Rows[0]["VentObject"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LoveMusicStyle"].ToString() != "")
                {
                    model.LoveMusicStyle = ds.Tables[0].Rows[0]["LoveMusicStyle"].ToString();
                }
                if (ds.Tables[0].Rows[0]["AddTime"].ToString() != "")
                {
                    model.AddTime = DateTime.Parse(ds.Tables[0].Rows[0]["AddTime"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        /// <param name="strWhere">Where条件</param>
        /// <returns>数据集</returns>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,UserName,UserPassword,Question,Answer,UserType,Integral,IsPass,NickName,HeahImagePath,Sex,Age,Occupation,QQ,MSN,Height,Tel,Measurements,Constellation,signa,AreaID,NowInThe,Looks,LoveState,Birth,School,PhoneModel,CardMumber,LoveSnacks,LoveStar,LoveCuisines,LoveMovie,LikeObject,MessObject,VentObject,LoveMusicStyle,AddTime ");
            strSql.Append(" FROM TB_User ");
            if (!string.IsNullOrEmpty(strWhere))
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        /// <param name="Top">条数</param>
        /// <param name="strWhere">Where条件</param>
        /// <param name="filedOrder">filedOrder排序</param>
        /// <returns>数据集</returns>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" ID,UserName,UserPassword,Question,Answer,UserType,Integral,IsPass,NickName,HeahImagePath,Sex,Age,Occupation,QQ,MSN,Height,Tel,Measurements,Constellation,signa,AreaID,NowInThe,Looks,LoveState,Birth,School,PhoneModel,CardMumber,LoveSnacks,LoveStar,LoveCuisines,LoveMovie,LikeObject,MessObject,VentObject,LoveMusicStyle,AddTime ");
            strSql.Append(" FROM TB_User ");
            if (!string.IsNullOrEmpty(strWhere))
            {
                strSql.Append(" where " + strWhere);
            }
            if (!string.IsNullOrEmpty(filedOrder))
            {
                strSql.Append(" order by " + filedOrder);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }


        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public Model.PageData GetList(int PageSize, int PageIndex, string strWhere, string filedOrder)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@sqlstr", SqlDbType.NVarChar, 4000),
                    new SqlParameter("@pageindex", SqlDbType.Int),
                    new SqlParameter("@pagesize", SqlDbType.Int),
                    };
            StringBuilder strSql = new StringBuilder("select * from TB_User ");
            if (!string.IsNullOrEmpty(strWhere))
            {
                strSql.Append(" where " + strWhere);
            }
            if (!string.IsNullOrEmpty(filedOrder))
            {
                strSql.Append(" order by " + filedOrder);
            }
            parameters[0].Value = strSql.ToString();
            parameters[1].Value = PageIndex;
            parameters[2].Value = PageSize;

            DataSet ds = DbHelperSQL.RunProcedure("SP_pagination", parameters, "ds");
            DataSet newds = new DataSet();
            newds.Tables.Add(ds.Tables[2].Copy());
            Model.PageData data = new Model.PageData();
            data.PageIndex = PageIndex;
            data.PageSize = PageSize;
            data.Count = Convert.ToInt32(ds.Tables[1].Rows[0]["Count"]);
            data.DataSoure = newds;

            return data;
        }

        #endregion  Method
    }
}

